package com.west_traveler.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

import java.util.Locale;

/**
 * Description: 常用工具类
 * Date:2016年12月06日15:40
 *
 * @author: 刘悦.
 */

public class CommonUtils {

    public static int getWindowWidth(Context context){

        WindowManager systemService = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = systemService.getDefaultDisplay();
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        return metrics.widthPixels;
    }

    public static String parseTime(int time) {
        time /= 1000;

        int minute = time / 60;
        int second = time % 60;
        int hour = minute / 60;
        minute %= 60;
        if (time > 3600) {
            return String.format(Locale.getDefault(), "%02d:%02d:%02d", hour, minute, second);
        } else {
            return String.format(Locale.getDefault(), "%02d:%02d", minute, second);
        }
    }
}
